home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / int13v20.arc / INT13.ASM next >
Assembly Source File  |  1985-12-06  |  16KB  |  466 lines

  1. PAGE 64,132
  2. ;
  3. ;         This program intercepts Int 13H calls and prints
  4. ;         the drive, side, track, sector, # of sectors, operation,
  5. ;         and return code.
  6. ;--------------------------------------------------------------
  7. DISKSTAT segment at 040h ;segment starts at abs. addr. 0400h
  8.          org 042h
  9. ST0      db ?        ;Disk status area used after 
  10. ST1      db ?        ;  int 13h calls
  11. ST2      db ?
  12. CYLINDER db ?
  13. HEAD     db ?
  14. RECORD   db ?
  15. NUMBER   db ?
  16. DISKSTAT ends
  17. ;--------------------------------------------------------------
  18. ;
  19. cseg    segment 
  20.         org 100h
  21. INT13   proc far
  22.         assume cs:cseg,ds:cseg
  23. ;
  24.         jmp install                    ;install and make routine resident
  25. ;
  26. redef13      label      word
  27. oldint13     dd         0              ;save area for old int13 vector
  28. int13loc     equ        13h*4h         ;vector location for int13h
  29. drive_a      equ         'A'
  30. drive_b      equ         'B'
  31. drive_c      equ         'C'
  32. drive_d      equ         'D'
  33. drive_x      equ         'X'
  34. save_ip      dw         0              ;save area for calling pgm's IP
  35. save_cs      dw         0              ;save area for calling pgm's CS
  36. save_st0     db         ?
  37. save_st1     db         ?
  38. save_st2     db         ?
  39. save_c       db         ?
  40. save_h       db         ?
  41. save_r       db         ?
  42. save_n       db         ?
  43. ;
  44. message      db 0fh        ;   code for compressed printing
  45.              db 'Drv: '
  46. drive        db ?
  47.              db ' Side: '
  48. side1        db ?
  49. side2        db ?
  50.              db '   Tr: '
  51. track1       db ?
  52. track2       db ?
  53.              db ' Sec: '
  54. sector1      db ?
  55. sector2      db ?
  56.              db '  # secs: '
  57. sec_cnt1     db ?
  58. sec_cnt2     db ?
  59.              db ' Op: '
  60. op_1         db ?
  61. op_2         db ?
  62.              db '   Retcd: '
  63. status1      db ?
  64. status2      db ?
  65.              db '  Addr: '
  66. cs_1         db ?
  67. cs_2         db ?
  68. cs_3         db ?
  69. cs_4         db ?
  70.              db ':'
  71. ip_1         db ?
  72. ip_2         db ?
  73. ip_3         db ?
  74. ip_4         db ?
  75.              db '  '     ;2 spaces
  76.              db ' ST0: '
  77. sto0_1       db ?
  78. sto0_2       db ?
  79.              db ' ST1: '
  80. sto1_1       db ?
  81. sto1_2       db ?
  82.              db ' ST2: '
  83. sto2_1       db ?
  84. sto2_2       db ?
  85.              db '  '     ;2spaces
  86.              db ' C: '
  87. c_1          db ?
  88. c_2          db ?
  89.              db ' H: '
  90. h_1          db ?
  91. h_2          db ?
  92.              db ' R: '
  93. r_1          db ?
  94. r_2          db ?
  95.              db ' N: '
  96. n_1          db ?
  97. n_2          db ?
  98.              db 0ah,0dh
  99. ;------------------------------
  100. unin_msg     db 'INT13 no longer active.......$'
  101. inst_msg     db 'INT13 is now installed.......$'
  102. ;
  103. newint13:
  104.         sti
  105.         push ax
  106.         push bp
  107.         mov bp,sp                      
  108.         mov ax,[bp+4]                  ;Retrieve return IP value 
  109.         mov cs:save_ip,ax              ;    from stack.
  110.         mov ax,[bp+6]                  ;Retrieve return CS value
  111.         mov cs:save_cs,ax              ;    from stack.
  112.         pop bp                         ;Save anything which will be
  113.         pop ax                         ;    be changed during
  114.         pushf                          ;    processing.
  115.         push di
  116.         push si
  117.         push ds
  118.         push es
  119.         push bx
  120.         push cx
  121.         push dx
  122.         push ax
  123.         mov ax,cs
  124.         mov ds,ax
  125. ;---------------DRIVE------------------
  126.         cmp dl,00h                     ;Drive A? (dl=00)
  127.         jne chk1                       ; Note: processing is in place for
  128.         mov drive,drive_a              ;    logging disk activity on all
  129.         jmp drv_exit                   ;    drives, if desired.  See below
  130. chk1:   cmp dl,01h                     ;Drive B?
  131.         jne chk2
  132.         mov drive,drive_b
  133.         jmp drv_exit
  134. chk2:   cmp dl,02h                     ;Drive C?
  135.         jne chk3
  136.         mov drive,drive_c
  137.         jmp drv_exit
  138. chk3:   cmp dl,03h
  139.         jne chkx
  140.         mov drive,drive_d
  141.         jmp drv_exit
  142. chkx:   mov drive,drive_x
  143. drv_exit:
  144. ;---------------SIDE  (DH) ------------
  145.         mov ah,dh                      ;record side being requested-left digit
  146.         call leftdig                   ;convert to ASCII code for printing
  147.         mov cs:side1,ah                ;move code to message area
  148.         mov ah,dh                      ;same for right digit
  149.         call rightdig
  150.         mov cs:side2,ah
  151. ;---------------TRACK NO. (CH)----------
  152.         mov ah,ch
  153.         call leftdig
  154.         mov cs:track1,ah
  155.         mov ah,ch
  156.         call rightdig
  157.         mov cs:track2,ah
  158. ;----------------------------------------
  159. ;
  160. ;----------------SECTOR NO. (CL)---------
  161.         mov ah,cl
  162.         call leftdig
  163.         mov cs:sector1,ah
  164.         mov ah,cl
  165.         call rightdig
  166.         mov cs:sector2,ah
  167. ;------------------------------------------
  168. ;
  169. ;----------------NO. OF SECTORS (AL)-------
  170. ;
  171.         pop ax      ;recall ax
  172.         push ax     ;save it again
  173.         mov ah,al
  174.         call leftdig
  175.         mov cs:sec_cnt1,ah
  176.         pop ax
  177.         push ax
  178.         mov ah,al
  179.         call rightdig
  180.         mov cs:sec_cnt2,ah
  181. ;--------------------------------------------------
  182. ;
  183. ;--------------OPERATION TYPE (AH)-----------------
  184. ; 00:reset 01:read status 02:read sectors 03:write sec. 04:verify 05:format
  185. ;
  186.  
  187.         pop ax      ;recall ax
  188.         push ax     ;save it again
  189.         call leftdig
  190.         mov cs:op_1,ah
  191.         pop ax
  192.         push ax
  193.         call rightdig
  194.         mov cs:op_2,ah
  195. ;-------------- RETURN ADDRESS CS:IP -------------------
  196. ;
  197.         mov ax,cs:save_ip
  198.         call leftdig
  199.         mov cs:ip_1,ah
  200.         mov ax,cs:save_ip
  201.         call rightdig
  202.         mov cs:ip_2,ah
  203.         mov ax,cs:save_ip
  204.         xchg ah,al
  205.         call leftdig
  206.         mov cs:ip_3,ah
  207.         mov ax,cs:save_ip
  208.         xchg ah,al
  209.         call rightdig
  210.         mov cs:ip_4,ah
  211. ;
  212.         mov ax,cs:save_cs
  213.         call leftdig
  214.         mov cs:cs_1,ah
  215.         mov ax,cs:save_cs
  216.         call rightdig
  217.         mov cs:cs_2,ah
  218.         mov ax,cs:save_cs
  219.         xchg ah,al
  220.         call leftdig
  221.         mov cs:cs_3,ah
  222.         mov ax,cs:save_cs
  223.         xchg ah,al
  224.         call rightdig
  225.         mov cs:cs_4,ah
  226. ;--------------------------------
  227.              pop ax                    ;Restore the things which were
  228.              pop dx                    ;    saved
  229.              pop cx
  230.              pop bx
  231.              pop es
  232.              pop ds
  233.              pop si
  234.              pop di
  235.              popf
  236. ;--------------------
  237.              pushf           ; Put flags, CS and IP onto stack for return to
  238.              push cs         ;  routine below after standard int 13h processing
  239.              call intcall    ; IP will point to next instruction
  240. ;
  241. ;---------------------------Report status of int 13h call----------
  242. ;
  243.              pushf
  244.              push bx
  245.              push ax                   ;Save it again
  246.              call leftdig
  247.              mov cs:status1,ah
  248.              pop ax
  249.              push ax
  250.              call rightdig
  251.              mov cs:status2,ah
  252. ;
  253. ;retrieve the status codes from 0442-0448h
  254. ;
  255.              push ds
  256.              assume ds:diskstat
  257.              mov ax,diskstat
  258.              mov ds,ax
  259.              mov ah,st0
  260.              mov cs:save_st0,ah
  261.              mov ah,st1
  262.              mov cs:save_st1,ah
  263.              mov ah,st2
  264.              mov cs:save_st2,ah
  265.              mov ah,cylinder
  266.              mov cs:save_c,ah
  267.              mov ah,head
  268.              mov cs:save_h,ah
  269.              mov ah,record
  270.              mov cs:save_r,ah
  271.              mov ah,number
  272.              mov cs:save_n,ah
  273.              pop ds
  274.              assume ds:cseg
  275. ;--------------
  276.              mov ah,cs:save_st0
  277.              call leftdig
  278.              mov cs:sto0_1,ah
  279.              mov ah,cs:save_st0
  280.              call rightdig
  281.              mov cs:sto0_2,ah
  282.                 mov ah,cs:save_st1
  283.                 call leftdig
  284.                 mov cs:sto1_1,ah
  285.                 mov ah,cs:save_st1
  286.                 call rightdig
  287.                 mov cs:sto1_2,ah
  288.                    mov ah,cs:save_st2
  289.                    call leftdig
  290.                    mov cs:sto2_1,ah
  291.                    mov ah,cs:save_st2
  292.                    call rightdig
  293.                    mov cs:sto2_2,ah
  294.              mov ah,cs:save_c
  295.              call leftdig
  296.              mov cs:c_1,ah
  297.              mov ah,cs:save_c
  298.              call rightdig
  299.              mov cs:c_2,ah
  300.                  mov ah,cs:save_h
  301.                  call leftdig
  302.                  mov cs:h_1,ah
  303.                  mov ah,cs:save_h
  304.                  call rightdig
  305.                  mov cs:h_2,ah
  306.                      mov ah,cs:save_r
  307.                      call leftdig
  308.                      mov cs:r_1,ah
  309.                      mov ah,cs:save_r
  310.                      call rightdig
  311.                      mov cs:r_2,ah
  312.                          mov ah,cs:save_n
  313.                          call leftdig
  314.                          mov cs:n_1,ah
  315.                          mov ah,cs:save_n
  316.                          call rightdig
  317.                          mov cs:n_2,ah
  318.              pop ax
  319.              pop bx
  320. ;------------  PRINT THE MESSAGE --------------------------
  321.              cmp dl,00h  ;******** REMOVE THESE TWO LINES IF YOU WISH
  322.              jne goback  ;********   ALL DISK ACTIVITY TO BE LOGGED
  323.              push ax
  324.              push cx
  325.              push dx
  326.              push si
  327.              mov cx,87h                ; Length of message
  328.              mov si,offset message
  329.              xor dx,dx
  330. prnloop:     mov ah,00h
  331.              mov al,cs:[si]  
  332.              int 17h
  333.              inc si
  334.              loop prnloop
  335.              pop si
  336.              pop dx
  337.              pop cx
  338.              pop ax
  339. goback:      popf
  340. ;-------------------------------------------------------
  341.              ret  2          ; Go back to calling program.
  342.                              ; Note:"iret" is not used because the flags
  343.                              ;   would be popped (and we wish to pass back
  344.                              ;   the changed set of flags).  The "2" ensures
  345.                              ;   that the stack is restored by incrementing
  346.                              ;   the stack pointer by two extra bytes.
  347. ;-----------------------
  348. intcall      PROC near     ; get set to go to standard int 13h routine
  349.              pushf
  350.              push cs:[redef13 + 2]     ; "cs" of int 13h routine
  351.              push cs:[redef13]         ; "ip" of int 13h routine
  352.              iret                      ; Branch to normal int13h code in ROM
  353. intcall      endp 
  354. ;--------------------------
  355. ;   Routine to convert high-order digit in AH to an ASCII character
  356. ;
  357. leftdig      PROC
  358.              and ah,11110000b ; Mask right 4 bits
  359.              shr ah,1         ; Move high-order digit to low-order pos.
  360.              shr ah,1
  361.              shr ah,1
  362.              shr ah,1
  363.              cmp ah,0ah       ; Check for value 0 through 9
  364.              jnb b37          ; If value hex A through F, jump 
  365.              add ah,30h       ; Add 30h to make ASCII character
  366.              jmp b2
  367.        b37:  add ah,37h       ; If hex A-F, add 37h to make ASCII character
  368.         b2:  ret
  369. leftdig      endp
  370. ;-----------------------
  371. ;   Routine to convert low-order digit in AH to an ASCII character
  372. ;
  373. rightdig     PROC near
  374.              and ah,00001111b ; mask left 4 bits
  375.              cmp ah,0ah
  376.              jnb a37
  377.              add ah,30h
  378.              jmp a1
  379.        a37:  add ah,37h
  380.         a1:  ret
  381. rightdig     endp
  382. ;-----------------------
  383. install:
  384.  
  385. ;     First, determine if INT13 has already been installed...
  386.              push ds                   ;Save DS
  387.              mov ax,0000h
  388.              mov ds,ax                 ;Need 0 in DS
  389.              mov di,int13loc           ;Move 4C to DI
  390.              mov bx,[di]               ;"IP" of current Int 13 routine
  391.              mov ax,[di+2]             ;"CS" of current Int 13 routine
  392.              mov ds,ax                 ;Establish new DS register value
  393.              mov ch,[bx-1]             ;Get byte just before entry point
  394.              pop ds                    ;Restore DS value at entry
  395.              cmp ch,024h               ;Look for a "$"
  396.              je un_inst                ;If =, then Int13 is already active
  397. ;     Proceed with installation 
  398.              mov ax,0
  399.              mov es,ax
  400.              mov di,int13loc           ;Save old 
  401.              mov ax,es:[di]            ;   interrupt 13h
  402.              mov bx,es:[di+2]          ;   vector
  403.              mov si,offset oldint13    ;     "
  404.              mov [si],ax               ;     "
  405.              mov [si+2],bx             ;     "
  406.              mov ax,0                  
  407.              mov es,ax
  408.              mov bx,ds
  409.              cli                       ;Turn off interrupts
  410.              mov di,int13loc           ;Change int13h ....
  411.              mov ax,offset newint13    ;   vector to...
  412.              mov es:[di],ax            ;   point to...
  413.              mov es:[di+2],bx          ;   this program.
  414.              sti                       ;Turn interrupts back on
  415.              mov dx,offset inst_msg
  416.              mov ah,09h                ;Print string function
  417.              int 21h                   ;Print "install" message
  418. ;
  419. ;---Check if compressed printing is to be disabled ("8" in parameter string)
  420. ;       Note: parameter string begins at offset 81h into COM file header,
  421. ;             and offset 80h contains length of parameter string.
  422. ;
  423.              mov ax,ds                 ;Make sure ES is the same
  424.              mov es,ax                 ;   as DS
  425.              cmp byte ptr es:[80h],00h ;Length of parm. string
  426.              je no_chng                ;If zero, no change
  427.              mov di,081h               ;Start of parm. string
  428.              mov al,038h               ;38h = "8"
  429.              xor ch,ch                 ;Zero high-order byte
  430.              mov cl,es:[80h]           ;Length of parm. string
  431.              cld                       ;Clear direction flag (forward)
  432.              repne scasb               ;Scan ES:DI 'til match with AL,or CX=0
  433.              jne no_chng               ;No match means "8" not in parm. strng
  434.              mov message,00h           ;"8" found, so zero out compress char.
  435. ;----------------------------------------------------------------------------
  436. no_chng:     mov dx,offset install     ;Address of end of resident routine
  437.              int 27h                   ;Terminate and stay resident
  438. ;
  439. ;----------------------------------------------------------------------------
  440. ;
  441. un_inst:     push ds                   ;Save DS again
  442.              mov ds,ax                 ;AX has CS value of current int 13
  443.              mov si,bx                 ;BX has entry point of current int 13
  444.              sub bx,0d2h               ;Backup D2 bytes to find "old" int 13
  445.              mov si,bx                 ;Establish "source" string start point
  446.              mov ax,0h
  447.              mov es,ax                 ;Zero out ES register for move
  448.              mov di,int13loc           ;Establish "destination" (004Ch)
  449.              mov cx,04h                ;4 bytes to move
  450.              cld                       ;Set forward direction for move
  451.              rep movsb                 ;Move from DS:SI to ES:DI until CX=0
  452. ;
  453. ;At this point, the int 13h vector at 0000:004C has been restored to
  454. ;       the value it had when INT13 was previously invoked.
  455. ;
  456.              pop ds                    ;Restore entry DS value
  457.              mov dx,offset unin_msg    ;Location of "un-install" message
  458.              mov ah,09h                ;Prepare for printing
  459.              int 21h                   ;Print the message
  460.              int 20h                   ;Terminate
  461. INT13        endp
  462. ;----------------------------------------------------------------------------
  463. cseg         ends
  464. end          INT13
  465.